<?php
include_once 'common/tools.php';

@ $userNo = $_GET["userNo"];
$userIp = $_SERVER["REMOTE_ADDR"];
$locale = $_GET["locale"];
$deviceId = $_GET["deviceId"];

$config = require 'conf/config.ini.php'; //加载公用config.ini.php
$conn = mysqli_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PWD"], $config["DB_NAME"]);


if ($userNo == "null") {
	$sql = "insert into live_welcome (userIp,locale,deviceId,updateDate) values ('" . $userIp . "', '" . $locale . "', '" . $deviceId . "', now())";
	mysqli_query($conn, "SET NAMES utf8");
	mysqli_query($sql, $conn);
}else{
	$sql = "SET NAMES gbk;";
	
	$userCity = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=" . $userIp);
	$userCity = explode("\t", $userCity);
	if($userCity[4] == "" && $userCity[5] == ""){
		$userCity = $userCity[3];
	}else{
		$userCity = $userCity[4] . ' ' . $userCity[5];
	}
	$sql .= "update live_user set userIp = '".$userIp."', userDeviceId = '". $deviceId ."', userCity = '". $userCity ."' where id = ". $userNo .";";
	$sql .= "insert into live_welcome (userNo,userIp,locale,deviceId,updateDate) values ('" . $userNo . "', '" . $userIp . "', '" . $locale . "', '" . $deviceId . "', now());";
	mysqli_multi_query($conn, $sql);
	echo '{"result":"'. $userCity .'"}';
}
?>